<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>功能分配</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css"
	href="../themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../themes/color.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../bootstrap/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../js/easyui-lang-zh_CN.js"></script>

<script type="text/javascript">
	$(function() {
		$("#ss")
				.click(
						function() {
							//	console.log("${ctx}");
							var url = "${ctx}/searchFunc";
							var params = {};
							params.rname = $("input[name='rname']").val();
							$
									.ajax({
										url : url,
										dataType : 'json',
										data : params,
										success : function(data) {
											if (data && data.length > 0) {
												var html = "";
												for (o in data) {
													console.log(data[o]);
													if (data[o].isselect == 1) {
														html += "<input type=\"checkbox\" value=\""+data[o].id+"\" checked=\"checked\" name=\"funcs\"/>";
													} else {
														html += "<input type=\"checkbox\" value=\""+data[o].id+"\" name=\"funcs\"/>";
													}
													html += data[o].text;
												}
												$("#showData").html(html);
											}
										}
									});
						});
		$(document).on("click", "#addordel", function() {
			var chk_value = [];

			$("input[name='funcs']:checked").each(function() {
				chk_value.push($(this).val());
			});
			var a = chk_value.join(",");
			// alert(a);
			var url = "${ctx}/updatefunc";
			var params = {};
			params.fname = a;
			params.rname = $("input[name='rname']").val();
			//params.rname='11'
			$.ajax({
				url : url,
				datatype : 'json',
				data : params,
				success : function(data) {
					alert("更新成功");
				}
			})
		})

	});
</script>
</head>

<body>

	<div style="text-align: center;">
		<p>功能分配</p>
		<form action="searchFunc">
			<div class="input-group">
				<input type="text" class="form-control" name="rname" /> <span
					class="input-group-btn"> <input id="ss"
					class="btn btn-default" type="button" value="搜索" />
				</span>
			</div>
		</form>

		<div style="margin: 20px 0;"></div>
		<div  class="easyui-panel" >
			<form action="updateFunc" method="post">
				<div id="showData" >
					<c:forEach items="${funcarray}" var="rfunction">
						<c:choose>
							<c:when test="${rfunction.isSelect=='1'}">
								${rfunction.fid}<input type="checkbox" value="${rfunction.fid}"
									checked="checked" name="funcs" />${rfunction.fname}
					</c:when>
							<c:otherwise>
								${rfunction.fid}<input type="checkbox" value="${rfuction.fid}"
									name="funcs" />${rfunction.fname}
					</c:otherwise>
						</c:choose>

					</c:forEach>
				</div>
				<input id="addordel" class="btn btn-default" type="button"
					value="提交" />

			</form>


		</div>
	</div>


</body>
</html>